{
  LX Vector module

  Based on modo's SDK lxvector.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Vector;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_Server, Lx_VMath;

const
  LXa_VECTORPACKET                              = 'vectorPacket' ;
  LXa_TEXTUREEFFECT                             = 'textureEffect';
  LXa_PACKETEFFECT                              = 'packetEffect' ;

  LXfVT_SET                                     = 1 shl 0;
  LXfVT_GET                                     = 1 shl 1;
  LXfVT_OPTIONAL                                = 1 shl 2;

  LXfRAY_SCOPE_POLYGONS                         = $00000001;
  LXfRAY_SCOPE_VOLUMETRICS                      = $00000002;
  LXfRAY_SCOPE_ENVIRONMENT                      = $00000004;
  LXfRAY_SCOPE_BACKFACE                         = $00000010;
  LXfRAY_SCOPE_BACKONLY                         = $00000020;
  LXfRAY_SCOPE_SAMESURF                         = $00000040;
  LXfRAY_SCOPE_IMPLICITSURF                     = $00000080;

  LXfRAY_EVAL_NORMAL                            = $00000100;
  LXfRAY_EVAL_MATERIAL                          = $00000200;
  LXfRAY_EVAL_OPACITY                           = $00000400;
  LXfRAY_EVAL_SHADING                           = $00000800;
  LXfRAY_EVAL_IRRADIANCE                        = $00001000;
  LXfRAY_EVAL_PERSPENV                          = $00002000;

  LXfRAY_TYPE_CAMERA                            = $00010000;
  LXfRAY_TYPE_SHADOW                            = $00020000;
  LXfRAY_TYPE_REFLECT                           = $00040000;
  LXfRAY_TYPE_REFRACT                           = $00080000;
  LXfRAY_TYPE_INDIRECT                          = $00100000;
  LXfRAY_TYPE_CAUSTIC                           = $00200000;
  LXfRAY_TYPE_SUBSURFACE                        = $00400000;
  LXfRAY_TYPE_SHADOWMAP                         = $00800000;
  LXfRAY_TYPE_TEXTURE                           = $01000000;
  LXfRAY_TYPE_OCCLUSION                         = $02000000;
  LXfRAY_TYPE_SHADOWVOL                         = $04000000;
  LXfRAY_TYPE_CLIPPING                          = $08000000;
  LXfRAY_TYPE_SHADOW_INFO                       = $10000000;

  LXfFACET_OBJECT_POSITION                      = $00000001;
  LXfFACET_DISPLACED                            = $00000002;
  LXfFACET_NORMALIZED                           = $00000004;

  LXfSURF_DOUBLE                                = $00000001;
  LXfSURF_TRANSP                                = $00000002;

  LXfSURF_SHADCAST                              = $00000010;
  LXfSURF_SHADRECV                              = $00000020;

  LXfSURF_VISCAM                                = $00000100;
  LXfSURF_VISIND                                = $00000200;
  LXfSURF_VISREFL                               = $00000400;
  LXfSURF_VISREFR                               = $00000800;
  LXfSURF_VISSUBS                               = $00001000;
  LXfSURF_VISOCCL                               = $00002000;

  LXfSURF_PHYSICAL                              = $00010000;
  LXfSURF_REFLSPEC                              = $00020000;
  LXfSURF_REFLBLUR                              = $00040000;
  LXfSURF_SAMESURF                              = $00080000;

  LXfSURF_TANSHADE                              = $00100000;
  LXfSURF_CLIPPING                              = $00200000;
  LXfSURF_CMPSHADE                              = $00400000;
  LXfSURF_IMPSHADE                              = $00800000;
  LXfSURF_CLPMATTE                              = $01000000;

  LXf_TFX_READ                                  = $10;
  LXf_TFX_WRITE                                 = $20;
  LXf_TFX_INPUT                                 = $40;
  LXf_TFX_BW                                    = $80;

  LXiTILE_RESET                                 = 0;
  LXiTILE_REPEAT                                = 1;
  LXiTILE_MIRROR                                = 2;
  LXiTILE_EDGE                                  = 3;

  LXi_FUR_GUIDE_NONE                            = 0;
  LXi_FUR_GUIDE_CLUMP                           = 1;
  LXi_FUR_GUIDE_NORMAL                          = 2;
  LXi_FUR_GUIDE_DIRLEN                          = 3;
  LXi_FUR_GUIDE_SHAPE                           = 4;
  LXi_FUR_GUIDE_INTERPOLATE                     = 5;

  LXi_FUR_BILLBOARD_OFF                         = 0;
  LXi_FUR_BILLBOARD_TREE                        = 1;
  LXi_FUR_BILLBOARD_LEAF                        = 2;

  LXi_TFX_SCALAR                                = 0;
  LXi_TFX_COLOR                                 = 1;

  LXsVPK_CATEGORY                               = 'vpacket.category';

  LXsCATEGORY_SAMPLE                            = 'sample';

  LXsP_SAMPLE_POSITION                          = 'sample.position';
  LXsP_SAMPLE_XFRM                              = 'sample.xfrm'    ;
  LXsP_SAMPLE_RAY                               = 'sample.ray'     ;
  LXsP_SAMPLE_CLIP                              = 'sample.clip'    ;
  LXsP_SAMPLE_PARMS                             = 'sample.parms'   ;
  LXsP_SAMPLE_MASK                              = 'sample.mask'    ;
  LXsP_SAMPLE_DRIVER                            = 'sample.driver'  ;
  LXsP_SAMPLE_STENCIL                           = 'sample.stencil' ;
  LXsP_SAMPLE_VOLUME                            = 'sample.volume'  ;
  LXsP_SAMPLE_DENSITY                           = 'sample.density' ;
  LXsP_SAMPLE_DISSOLVE                          = 'sample.dissolve';
  LXsP_SAMPLE_FACET                             = 'sample.facet'   ;
  LXsP_SAMPLE_BUMP                              = 'sample.bump'    ;

  LXsP_TEXTURE_INPUT                            = 'texture.input'  ;
  LXsP_TEXTURE_OUTPUT                           = 'texture.output' ;
  LXsP_TEXTURE_VALUE                            = 'texture.value'  ;
  LXsP_TEXTURE_LOCATOR                          = 'texture.locator';

  LXsP_SURF_NORMAL                              = 'surface.normal'   ;
  LXsP_SURF_SMOOTH                              = 'surface.smoothing';

  LXsP_DISPLACE                                 = 'displace'  ;
  LXsP_SHADER_TYPE                              = 'shaderType';
  LXsP_GROUP_LAYER                              = 'groupLayer';

  LXsP_FUR_PARMS                                = 'fur'           ;
  LXsP_PARTICLE_SAMPLE                          = 'particleSample';

  LXsP_SHADE_OPACITY                            = 'shade.opacity'     ;
  LXsP_SHADE_COMPONENTS                         = 'shade.components'  ;
  LXsP_SHADE_OUTPUT                             = 'shade.output'      ;
  LXsP_SHADE_DIFFUSE                            = 'shade.diffuse'     ;
  LXsP_SHADE_SPECULAR                           = 'shade.specular'    ;
  LXsP_SHADE_MIRROR                             = 'shade.mirror'      ;
  LXsP_SHADE_TRANSPARENCY                       = 'shade.transparency';
  LXsP_SHADE_SUBSURFACE                         = 'shade.subsurface'  ;
  LXsP_SHADE_LUMINOSITY                         = 'shade.luminosity'  ;

  LXsP_SHADE_FLAGS                              = 'surfFlags';
  LXsP_SHADE_FOG                                = 'surfFog'  ;

  SVPs_SURF_FOG                                 = LXsP_SHADE_FOG;

  LXs_FX_ANISODIR                               = 'anisoDir'           ;
  LXs_FX_BUMP                                   = 'bump'               ;
  LXs_FX_COATAMOUNT                             = 'coatAmount'         ;
  LXs_FX_DIFFAMOUNT                             = 'diffAmount'         ;
  LXs_FX_DIFFCOLOR                              = 'diffColor'          ;
  LXs_FX_DIFFROUGH                              = 'diffRough'          ;
  LXs_FX_DISPLACE                               = 'displace'           ;
  LXs_FX_DRIVERA                                = 'driverA'            ;
  LXs_FX_DRIVERB                                = 'driverB'            ;
  LXs_FX_DRIVERC                                = 'driverC'            ;
  LXs_FX_DRIVERD                                = 'driverD'            ;
  LXs_FX_ENVALTITUDE                            = 'envAltitude'        ;
  LXs_FX_ENVCOLOR                               = 'envColor'           ;
  LXs_FX_GROUPMASK                              = 'groupMask'          ;
  LXs_FX_LAYERMASK                              = 'layerMask'          ;
  LXs_FX_LUMIAMOUNT                             = 'lumiAmount'         ;
  LXs_FX_LUMICOLOR                              = 'lumiColor'          ;
  LXs_FX_NORMAL                                 = 'normal'             ;
  LXs_FX_SPECAMOUNT                             = 'specAmount'         ;
  LXs_FX_SPECCOLOR                              = 'specColor'          ;
  LXs_FX_SPECFRESNEL                            = 'specFresnel'        ;
  LXs_FX_STENCIL                                = 'stencil'            ;
  LXs_FX_REFLAMOUNT                             = 'reflAmount'         ;
  LXs_FX_REFLCOLOR                              = 'reflColor'          ;
  LXs_FX_REFLFRESNEL                            = 'reflFresnel'        ;
  LXs_FX_ROUGH                                  = 'rough'              ;
  LXs_FX_SUBSAMOUNT                             = 'subsAmount'         ;
  LXs_FX_SUBSCOLOR                              = 'subsColor'          ;
  LXs_FX_SP_DENSITY                             = 'surfParticleDensity';
  LXs_FX_SP_NORMAL                              = 'surfParticleNormal' ;
  LXs_FX_SP_HEADING                             = 'surfParticleHeading';
  LXs_FX_SP_SIZE                                = 'surfParticleSize'   ;
  LXs_FX_PART_DENS                              = 'particleDensity'    ;
  LXs_FX_PART_DISS                              = 'particleDissolve'   ;
  LXs_FX_PART_SIZE                              = 'particleSize'       ;
  LXs_FX_TRANAMOUNT                             = 'tranAmount'         ;
  LXs_FX_TRANCOLOR                              = 'tranColor'          ;
  LXs_FX_TRANROUGH                              = 'tranRough'          ;
  LXs_FX_VECDISP                                = 'vectorDisplace'     ;
  LXs_FX_RGBA                                   = 'RGBA'               ;
  LXs_FX_DISSOLVE                               = 'dissolve'           ;

  LXs_FX_FUR_BEND                               = 'furBend'        ;
  LXs_FX_FUR_BUMP                               = 'furBump'        ;
  LXs_FX_FUR_CLDENS                             = 'furClumpDensity';
  LXs_FX_FUR_CLUMPS                             = 'furClumps'      ;
  LXs_FX_FUR_CURLS                              = 'furCurls'       ;
  LXs_FX_FUR_CYLINDERS                          = 'cylinders'      ;
  LXs_FX_FUR_DENSITY                            = 'furDensity'     ;
  LXs_FX_FUR_DIRECTION                          = 'furDirection'   ;
  LXs_FX_FUR_FLEX                               = 'furFlex'        ;
  LXs_FX_FUR_GROWJIT                            = 'furGrowthJitter';
  LXs_FX_FUR_KINK                               = 'furKink'        ;
  LXs_FX_FUR_FRIZZ                              = 'furFrizz'       ;
  LXs_FX_FUR_KINK_TIP                           = 'furKinkTip'     ;
  LXs_FX_FUR_FRIZZ_TIP                          = 'furFrizzTip'    ;
  LXs_FX_FUR_STRAYS                             = 'furStrays'      ;

  LXs_FX_FUR_GUIDE_NONE                         = 'none'  ;
  LXs_FX_FUR_GUIDE_DIRLENGTH                    = 'dirlen';
  LXs_FX_FUR_GUIDE_SHAPE                        = 'shape' ;
  LXs_FX_FUR_GUIDE_RANGE                        = 'range' ;
  LXs_FX_FUR_GUIDE_DIRECTION                    = 'normal';
  LXs_FX_FUR_GUIDE_CLUMP                        = 'clump' ;

  LXs_FX_FUR_LENGTH                             = 'furLength';
  LXs_FX_FUR_STRIPS                             = 'strips'   ;
  LXs_FX_FUR_VECTOR                             = 'furVector';

  LXs_FX_OUTPUT_FINAL_COLOR                     = 'shade.color'       ;
  LXs_FX_OUTPUT_ALPHA                           = 'shade.alpha'       ;
  LXs_FX_OUTPUT_DIFFUSE_SHADING_TOTAL           = 'shade.diffuse'     ;
  LXs_FX_OUTPUT_DIFFUSE_SHADING_DIRECT          = 'shade.diffDir'     ;
  LXs_FX_OUTPUT_DIFFUSE_SHADING_INDIRECT        = 'shade.diffInd'     ;
  LXs_FX_OUTPUT_DIFFUSE_SHADING_UNSHADOWED      = 'shade.diffUns'     ;
  LXs_FX_OUTPUT_SPECULAR_SHADING                = 'shade.specular'    ;
  LXs_FX_OUTPUT_REFLECTION_SHADING              = 'shade.reflection'  ;
  LXs_FX_OUTPUT_TRANSPARENT_SHADING             = 'shade.transparency';
  LXs_FX_OUTPUT_SUBSURFACE_SHADING              = 'shade.subsurface'  ;
  LXs_FX_OUTPUT_LUMINOUS_SHADING                = 'shade.luminosity'  ;

  LXs_FX_OUTPUT_VOL_SCATTERING                  = 'volume.scattering';
  LXs_FX_OUTPUT_VOL_OPACITY                     = 'volume.opacity'   ;
  LXs_FX_OUTPUT_VOL_DEPTH                       = 'volume.depth'     ;

  LXs_FX_OUTPUT_DEPTH                           = 'depth' ;
  LXs_FX_OUTPUT_MOTION                          = 'motion';
  LXs_FX_OUTPUT_SHADOW_DENSITY                  = 'shadow';

  LXs_FX_OUTPUT_AMBIENT_OCCLUSION               = 'occl.ambient';
  LXs_FX_OUTPUT_REFLECTION_OCCLUSION            = 'occl.reflect';

  LXs_FX_OUTPUT_SHADING_NORMAL                  = 'shade.normal'   ;
  LXs_FX_OUTPUT_SHADING_INCIDENCE               = 'shade.incidence';

  LXs_FX_OUTPUT_GEOMETRIC_NORMAL                = 'geo.normal' ;
  LXs_FX_OUTPUT_SURFACE_ID                      = 'geo.surface';
  LXs_FX_OUTPUT_SEGMENT_ID                      = 'geo.segment';
  LXs_FX_OUTPUT_OBJECT_COORDINATES              = 'geo.object' ;
  LXs_FX_OUTPUT_WORLD_COORDINATES               = 'geo.world'  ;
  LXs_FX_OUTPUT_UV_COORDINATES                  = 'geo.uv'     ;
  LXs_FX_OUTPUT_DPDU_VECTOR                     = 'geo.dpdu'   ;
  LXs_FX_OUTPUT_DPDV_VECTOR                     = 'geo.dpdv'   ;

  LXs_FX_OUTPUT_IC_POSITIONS                    = 'ic.position';
  LXs_FX_OUTPUT_IC_VALUES                       = 'ic.value'   ;

  LXs_FX_OUTPUT_DIFFUSE_COEFFICIENT             = 'mat.diffuse'   ;
  LXs_FX_OUTPUT_SPECULAR_COEFFICIENT            = 'mat.specular'  ;
  LXs_FX_OUTPUT_REFLECTION_COEFFICIENT          = 'mat.reflection';

  LXs_FX_OUTPUT_ILLUMINATION_SHADING_TOTAL      = 'shade.illum'   ;
  LXs_FX_OUTPUT_ILLUMINATION_SHADING_DIRECT     = 'shade.illumDir';
  LXs_FX_OUTPUT_ILLUMINATION_SHADING_INDIRECT   = 'shade.illumInd';
  LXs_FX_OUTPUT_ILLUMINATION_SHADING_UNSHADOWED = 'shade.illumUns';
  LXs_FX_OUTPUT_SHADING_SAMPLES                 = 'shade.samples' ;

  LXs_FX_SHADER_FULL_SHADING                    = 'fullShade';
  LXs_FX_SHADER_DIFFUSE_SHADING                 = 'diffShade';
  LXs_FX_SHADER_SPECULAR_SHADING                = 'specShade';
  LXs_FX_SHADER_REFLECTION_SHADING              = 'reflShade';
  LXs_FX_SHADER_TRANSPARENT_SHADING             = 'tranShade';
  LXs_FX_SHADER_SUBSURFACE_SHADING              = 'subsShade';
  LXs_FX_SHADER_LUMINOUS_SHADING                = 'lumiShade';
  LXs_FX_SHADER_FOG_SHADING                     = 'fogShade' ;

  LXsSHADE_SURFACE                              = 'surface'    ;
  LXsSHADE_LIGHT                                = 'light'      ;
  LXsSHADE_ENVIRONMENT                          = 'environment';
  LXsSHADE_PROCEDURAL                           = 'procedural' ;
  LXsSHADE_OUTPUT                               = 'output'     ;
  LXsSHADE_CAMERA                               = 'camera'     ;
  LXsSHADE_SCENE                                = 'scene'      ;

  LXsTFX_CATEGORY                               = 'textureFX.category';

  LXu_PACKETSERVICE = '{2B8D8867-4EFC-4A1D-8F6A-B5F103A90A9B}';
  LXu_PACKETEFFECT  = '{7e8a37ce-618b-4ae4-a429-01317ac40eb0}';
  LXu_TEXTUREEFFECT = '{CA13032E-3855-4744-B77A-59530EC3E260}';
  LXu_VECTORPACKET  = '{F74C2B0E-4BC5-4E76-8F7D-1D64DA86FD28}';
  LXu_VECTORLIST    = '{F091C272-C770-42C3-B314-62EE90D34C57}';
  LXu_VECTORSTACK   = '{7915D133-4272-498B-A691-C98118F40FD5}';
  LXu_VECTORTYPE    = '{791B288F-DD69-11D7-857A-000A9593D716}';

 type
  PLXtGenVector    = ^LXtGenVector;
  LXtGenVector     = record    end;

  PLXtSampleVector = ^LXtSampleVector;
  LXtSampleVector  = record       end;

  PLXpSamplePostion = ^LXpSamplePosition;
  LXpSamplePosition = record
    WPos     ,               // position in world space
    WVel     ,               // velocity in world space (meters traveled during exposure)
    OPos     ,               // position in object space
    UPos     : LXtVector  ;  // undisplaced position in object space
    Spot     ,               // spot size (width of sample perpendicular to incoming ray)
    Bias     : Single     ;  // distance by which wPos is adjusted to prevent self-shadowing
    Infinite : Integer    ;  // indicates an environment sample
    UV       ,               // variable-length UV array
    DUV      : PSingle    ;  // variable-length UV delta array (like RenderMan's du and dv)
    DPDUV    : PLXtFVector;  // variable-length UV derivative array (like RenderMan's dPdu and dPdv)
    Offset   : PInteger   ;  // variable-length feature offsets
  end;

  PLXpSampleTransform = ^LXpSampleTransform;
  LXpSampleTransform  = record
    Transform ,             // direct transformation
    Invert    : LXtMatrix;  // inverse transformation
    Scale     ,             // object scale
    WPos      : LXtVector;  // object world position
  end;

  PLXpSampleRay = ^LXpSampleRay;
  LXpSampleRay  = record
    Origin     : LXtVector ;  // origin of the ray (position)
    Dir        ,              // direction of the ray
    Color      ,              // color seen by the ray
    Abc        : LXtFVector;  // absorption coefficients
    Dist       ,              // distance travelled by the ray
    PrevDist   ,              // total distance travelled by previous segments of the ray
    NearClip   ,              // near
    FarClip    ,              // and far clipping distances
    Importance ,              // starts at one, then diminishes as the ray tree splits
    PrevSpot   ,              // spot size of ray at its origin
    Cone       ,              // cone angle of the ray (spot = prevSpot + dist * cone)
    ETA        ,              // refractive index of the material in which the ray is traveling
    Wavelength : Single    ;  // wavelength in nanometers for monochromatic dispersion rays
    Bounces    ,              // number of bounces
    Thread     : Integer   ;  // thread number
    Flags      : UInt32    ;  // ray evaluation flags (see REf_xxx in rays.qq)
    RayID      : Integer   ;  // number of this ray (as a uniqueness identifier)
  end;

  PLXpSampleClip = ^LXpSampleClip;
  LXpSampleClip  = record
    ELT   : Pointer;  // clipping element ID
    Dist  ,           // clip distance on the ray
    Delta : Single ;  // difference between original and modified sample position on the ray
  end;

  PLXpSampleParms = ^LXpSampleParms;
  LXpSampleParms  = record
    DiffCol    ,              // diffuse color
    SpecCol    ,              // specular color
    ReflCol    ,              // mirror reflection color
    TranCol    ,              // transparency color
    SubsCol    ,              // subsurface scattering color
    LumiCol    ,              // luminous color
    ExitCol    ,              // exit color
    ClipCol    ,              // clipping color
    AnisoDir   ,              // anisotropy direction (raw color)
    AnisoDPDU  ,              // anisotropy U derivative
    AnisoDPDV  : LXtFVector;  // anisotropy V derivative
    DiffAmt    ,              // diffuse amount
    SpecAmt    ,              // specular amount
    ReflAmt    ,              // mirror reflection amount
    TranAmt    ,              // transparency amount
    SubsAmt    ,              // subsurface scattering amount
    LumiAmt    ,              // luminous amount
    CoatAmt    ,              // clearcoat amount
    DissAmt    ,              // dissolve amount
    BumpAmt    ,              // bump strength
    BumpAmp    ,              // bump amplitude
    DiffRough  ,              // diffuse roughness (for Oren-Nayar BRDF)
    ClipVal    ,              // clipping value associated to material
    Rough      ,              // roughness value before it is converted into specular exponents
    Aniso      ,              // anisotropy strength (variation of U and V specular exponents)
    AnisoCos   ,              // anisotropy direction cosine
    AnisoSin   ,              // anisotropy direction sine
    SpecExpU   ,              // specular exponent in U direction
    SpecExpV   ,              // specular exponent in V direction
    SpecFres   ,              // specular fresnel amount
    ReflFres   ,              // reflection fresnel amount
    RefIndex   ,              // refractive index
    Disperse   ,              // dispersion (variation of refractive index with wavelength)
    TranRough  ,              // transparency roughness
    TranDist   ,              // absorption distance
    SubsDist   ,              // scattering distance
    SubsDepth  ,              // scattering max depth
    SubsPhase  : Single    ;  // scattering phase function (forward/backward balance)
    ReflType   ,              // reflection type
    ReflRays   ,              // reflection rays
    TranRays   ,              // refraction rays
    SubsRays   ,              // subsurface scattering rays
    Flags      ,              // give shaders access to LXfSURF_* flags
    UVOffset   ,              // offset used to get u,v derivatives
    ClearBump  ,              // clear pre existing bumps
    ClipEnable ,              // enable render clipping on surface
    ClipMatte  ,              // render clip surface as matte color
    Clipped    : Integer   ;  // surface sample is clipped
  end;

  PLXpSampleMask = ^LXpSampleMask;
  LXpSampleMask  = record
    GroupOpacity  ,           // the opacity for a shader group
    LayerOpacity  : Single ;  // the opacity for a layer
    LayerOverride : Integer;  // true if the layer evaluation should use the layerOpacity
  end;

  PLXpSampleGroupMask = ^ LXpSampleGroupMask;
  LXpSampleGroupMask  = record
    GroupOpacity : Single;  // the opacity for a shader group
  end;

  PLXpSampleDriver = ^LXpSampleDriver;
  LXpSampleDriver  = record
    A, B, C, D : Single;
  end;

  PLXpSampleStencil = ^LXpSampleStencil;
  LXpSampleStencil  = record
    Value        : Single ;
    TextureCount ,
    TexturePass  : Integer;
  end;

  PLXpSampleVolume = ^LXpSampleVolume;
  LXpSampleVolume  = record
    Scatter    ,
    Absorb     ,
    Ambient    : LXtFVector; // Added in SDK 52162
    ScatterAmt ,
    AbsorbAmt  ,
    Attenuate  ,
    Shift      : Single    ;
  end;

  PLXpSampleDensity = ^LXpSampleDensity;
  LXpSampleDensity  = record
    Density  ,
    Density0 ,
    Level    : Single;
  end;

  PLXpSampleDissolve = ^LXpSampleDissolve;
  LXpSampleDissolve  = record
    Dissolve : Single;
  end;

  PLXpSampleFacet = ^LXpSampleFacet;
  LXpSampleFacet  = record
    WPos  : array [0..2] of LXtVector;  // position in world space (note that we have to use double precision)
    OPos  : array [0..2] of LXtVector;  // position in object space
    UPos  : array [0..2] of LXtVector;  // undisplaced position in object space
    Flags : Integer  		     ;  // facet flags
  end;

  PLXpSampleBump = ^LXpSampleBump;
  LXpSampleBump  = record
    DP            : LXtVector;  // position delta during bump map evaluation
    Bump          : LXtVector;  // this is the result of bump map evaluation: the bumped normal
    BumpAmplitude : Single   ;  // bump amplitude as set by the material
    BumpHeight    : Single   ;  // bump height at sample position
    BumpMapping   ,             // flag set to true during bump mapping texture evaluation
    TexturePass   ,             // flag set to true during bump texture count pass
    TextureCount  ,             // bump texture count
    ShadeCount    ,             // shader counter
    ShadeIndex    : Integer  ;  // current shader evaluation index
  end;

  PLXpTextureInput = ^LXpTextureInput;
  LXpTextureInput  = record
    TPos           ,                           // position in texture space
    UVW            ,                           // UVW coordinates computed from projection
    UVW0           ,                           // raw UVW coordinates (before wrapping, repeat options, etc)
    Scale          ,                           // texture scale
    DPDU, DPDV     : LXtFVector             ;  // U,V derivatives
    TSize          : array [0..1] of Single ;
    TSpot          : Single                 ;  // texture spot size
    OctaveMult     : Single                 ;  // multiplier on the number octaves for fractal textures, always between (0,1). Similar to importance but for textures
    AdaptiveFreq   ,                           // enables the adpative frequencies on fractal textures.
    Context        ,                           // eval context
    Axis           ,                           // texture axis (from the locator)
    UVOffset       : Integer                ;  // offset of the uvs to use for evaluation
    UVTile         : array [0..1] of Integer;  // UV tiling options.
    UVWrap         : array [0..1] of Single ;  // UV wrapping sizes
    UVXfrm         : LXtMatrix              ;  // UV transformation matrix
    NoTile         ,                           // should be set to ignore UV tiling options (used in GL context)
    ProjOnly       ,                           // true when the texture requires a projection, like image maps
    SampleMesh     ,                           // flag which should be set when doing sample mesh previews
    IgnoreAlpha    : Integer                ;  // flag which should be set when doing sample mesh previews
    SampleScale    : Single                 ;  // scale of the sample mesh
    OffRange       : Integer                ;  // some projections may decide to render nothing outside the [0,1] UV range. In that case 'offRange' will be true
    IDParm         : Single                 ;  // texture particle ID parameter as set during texture replication (note that it is not the same as the surface particle ID)
    ParticleIdx    ,                           // texture particle index in the particle array
    ParticleEval   : Integer                ;  // particle context flag set to true when evaluating particles, this can trigger specialised evaluations modes
    ParticleRadius : Single                 ;  // particle radius
  end;

  PLXpTextureOutput = ^LXpTextureOutput;
  LXpTextureOutput  = record
    Direct : Integer                  ;
    Value  : array [0..1] of Double   ;
    Color  : array [0..1] of LXtVector;
    Alpha  : array [0..1] of Double   ;
    Range  : array [0..1] of Double   ;
    Blend  : Double                   ;
  end;

  PLXpTextureValue = ^LXpTextureValue;
  LXpTextureValue  = record
    Value ,
    Alpha : Double   ;
    Color : LXtVector;
  end;

  PLXpTextureLocator = ^LXpTextureLocator;
  LXpTextureLocator  = record
    WPos   ,
    OPos   : LXtVector;
    Xfrm   ,
    IXfrm  ,
    IRXfrm : LXtMatrix;
  end;

  PLXpSampleSurfNormal = ^LXpSampleSurfNormal;
  LXpSampleSurfNormal  = record
    GNorm     ,              // geometric normal (without smoothing)
    UNorm     ,              // undisplaced normal (with smoothing but no displacement)
    WNorm0    ,              // initial shading normal (with smoothing but no bump textures)
    WNorm     ,              // final shading normal (with smoothing and bump textures)
    Tangent   ,              // tangent vector, used by hair rendering
    NormalMap : LXtFVector;  // normal vector evaluated by normal map textures
    OAxis     ,
    WAxis     ,              // dominant axis in object and world space
    Back      : Integer   ;  // true if surface is backfacing
  end;

  PLXpSampleSurfSmooth = ^LXpSampleSurfSmooth;
  LXpSampleSurfSmooth  = record
    Smooth,
    CSA      : Single ;
    DblSided : Integer;
  end;

  PLXpDisplace = ^LXpDisplace;
  LXpDisplace  = record
    DPos      ,              // displaced position
    VDsp      : LXtFVector;  // vector displacement (set by textures)
    Max       ,              // max displacement
    Amplitude ,              // displacement amplitude (set by the material)
    Dist      : Single    ;  // displacement height (set by textures)
    Enable    ,              // enable flag set to true by displacement textures (so 0 means no displacement textures).
    MaxPass   : Integer   ;  // true during the 'max' evaluation pass
  end;

  PLXpShaderType = ^LXpShaderType;
  LXpShaderType  = record
    &Type      ,
    Hidden     ,
    LayerIndex : Integer;
  end;

  PLXpGroupLayer = ^LXpGroupLayer;
  LXpGroupLayer  = record
    LayerEnum  ,           // layer enumeration flag
    LayerScope ,           // enumeration scope
    LayerCount ,           // number of layers
    LayerIndex ,           // current layer evaluation index
    LayerTotal : Integer;  // total number of groups with scope
  end;

  PLXpFurParms = ^LXpFurParms;
  LXpFurParms  = record
    MinDist         ,              // minimum distance between hairs at 100% density
    Length	    ,              // hair length
    Width           ,              // hair width at root (percent of distance parameter)
    Flex            ,              // how much hair flexes
    Density         ,              // hair density
    Display         ,              // display density (percen of main density)
    BumpAmp         ,              // bump amplitude for fur bump effects
    Curles          ,              // curles amplitude
    Clumps          ,              // clumps amplitude
    ClumpDens       ,              // clumps density
    ClumpSize       ,              // clump range (m)
    ClumpStray      ,              // clump stray hair probability
    ClumpStrayAmp   ,              // clump stray strength
    Taper           ,              // taper
    YOffset         ,              // vertical offset (m)
    StripRot        ,              // strip random rotation (%)
    RootBend        ,              // root bending (%)
    Rate            ,              // fur rate for adaptive sampling
    BlendAngle      ,              // the limit angle for guide blending
    BlendAmount     : Single    ;  // the amount of guide blending
    PosJitter       ,              // jittering for position scale and orientation and growth
    SclJitter       ,
    NrmJitter       ,
    GrwJitter       : Single    ;
    KinkAmp         ,              // kink amplitude at the root, amplitude at the tip, scale, y scale, offset
    KinkAmpTip      ,
    KinkScl         ,
    KinkYScl        ,
    KinkOff         : Single    ;
    FrizAmp         ,              // frizz amplitude at the root, amplitude at the tip, scale and offset
    FrizAmpTip      ,
    FrizScl         ,
    FrizOff         : Single    ;
    MaxSegment      ,              // maximum number of segments long one hair
    &Type           ,              // geometry type
    FurOnly         ,              // remove base surface polygons when true
    RandomSeed      ,              // seed for fur random sequence
    Adaptive        ,              // adaptive fur flag
    AutoFade        ,              // automatic fading (for adaptive fur) flag
    Culling         ,              // view frustrum culling flag
    Billboard       ,              // true for billboard type geometry, can be either tree or leaf.
                                   // The difference is the direction: trees grow up and facing the camera
                                   // and leaves grow horizontal, not facing the camera.
    GLColorOverride ,              // true if GL should use color below
    UseIC           : Integer   ;  // true if IC should be enabled on fur (OFF by default)
    GLColor         : LXtFVector;  // GL color for hair strands
    // guide settings
    Guides          ,              // how to use guides for fur geometry
    GuideSurf       ,              // true if the guides are located in the same surface (as the fur)
    GuideBound      : Integer   ;  // true if surface guides need to be included in surface bounding box
    GuideSize       ,              // guide range (m)
    GuideLen        : Single    ;  // guide parametric length (%)
    GuideTag        : PChar     ;  // guide polygon tag
    GuideType       : LXtID4    ;  // guide polygon tag type
    GuideItem       : Pointer   ;  // guide mesh item
    // eval data
    Bump            : LXtFVector;  // fur bump vector
    BumpHeight      ,              // evaluated bump height
    Max             ,              // max fur size
    Dist            : Single    ;  // fur height (set by textures)
    Enable          ,              // enable flag set to true by fur materials (so 0 means no fur material).
    Cylinders       ,              // true if hairs are made of cylinders
    TgtShade        ,              // true if fur uses tangent shading
    MaxPass         ,              // true during the 'max' evaluation pass
    BumpPass        : Integer   ;  // true during the 'fur bump' evaluation pass
  end;

  PLXpParticleSample = ^LXpParticleSample;
  LXpParticleSample  = record
    Vel      ,              // instant velocity
    Normal   ,              // hair normal
    Bump     : LXtFVector;  // hair bump
    IDParm   ,
    LenParm  ,
    MinDist  ,
    Density  ,
    Size     ,
    Dissolve ,
    Age      : Single    ;
    UseLen   : Integer   ;
    // Particle implicit UVs
    UV       : array [0..1] of Single;
    DUV      : array [0..1] of Single;
    DPDU     : array [0..1] of Single;
    PDV      : array [0..1] of Single;
  end;

  PLXpShadeOpacity = ^LXpShadeOpacity;
  LXpShadeOpacity  = record
    Opa : LXtFVector;
  end;

  PLXpShadeComponents = ^LXpShadeComponents;
  LXpShadeComponents  = record
    Diff     ,              // diffuse reflection
    DiffDir  ,              // diffuse (direct illumination only)
    DiffInd  ,              // diffuse (indirect illumination only)
    DiffUns  ,              // diffuse (unshadowed direct illumination)
    Spec     ,              // specular reflection
    Refl     ,              // mirror reflection
    Tran     ,              // transparency
    Subs     ,              // subsurface scattering
    Lumi     ,              // luminosity
    Illum    ,              // total illumination
    IllumDir ,              // direct illumination only
    IllumInd ,              // indirect illumination only
    IllumUns ,              // unshadowed direct illumination
    VolLum   ,              // volumetic scattering
    VolOpa   : LXtFVector;  // volumetric absorption
  end;

  PLXpShadeOutput = ^LXpShadeOutput;
  LXpShadeOutput  = record
    Color    ,              // final color
    MVec     ,              // motion vector
    SNorm    ,              // shading normal
    GNorm    ,              // geometric normal
    UV       ,              // UV coordinates
    DPDU     ,              // dPdu vector
    DPDV     ,              // dPdv vector
    ICVal    : LXtFVector;  // nearest IC value
    Alpha    ,              // alpha channel
    Depth    ,              // depth from camera
    VolDepth ,              // depth from camera for volume samples
    Shadow   ,              // shadow density
    OcclAmb  ,              // ambient occlusion
    OcclRef  ,              // reflection occlusion
    SInc     : Single    ;  // incidence based on shading normal
  end;

  PLXpShadeDiffuse = ^LXpShadeDiffuse;
  LXpShadeDiffuse  = record
    Val : LXtFVector;
  end;

  PLXpShadeSpecular = ^LXpShadeSpecular;
  LXpShadeSpecular  = record
    Val : LXtFVector;
  end;

  PLXpShadeMirror = ^LXpShadeMirror;
  LXpShadeMirror  = record
    Val : LXtFVector;
  end;

  PLXpShadeTransparency = ^LXpShadeTransparency;
  LXpShadeTransparency  = record
    Val : LXtFVector;
  end;

  PLXpShadeSubsurface = ^LXpShadeSubsurface;
  LXpShadeSubsurface  = record
    Val : LXtFVector;
  end;

  PLXpShadeLuminosity = ^LXpShadeLuminosity;
  LXpShadeLuminosity  = record
    Val : LXtFVector;
  end;

  PLXpShadeFlags = ^LXpShadeFlags;
  LXpShadeFlags  = record
    LightGroup  : Pointer              ;
    ShadeRate   ,
    DirMult     ,
    IndMult     ,
    IndSat      ,
    AlphaVal    ,
    ETA         ,
    RndWidth    : Single               ;
    IndType     ,
    AlphaType   ,
    LightLink   ,
    Flags       : UInt32               ;
    ShadeEffect : array [0..31] of Char;
  end;

  PLXpShadeFog = ^LXpShadeFog;
  LXpShadeFog  = record
    FogCol     : LXtFVector;
    FogStart   ,
    FogEnd     ,
    FogDensity : Single    ;
    FogType    ,
    FogEnv     : UInt32    ;
  end;

  ILxVectorPacket = interface
  [LXu_VECTORPACKET]
    function  Size                                   : UInt32  ;
    function  &Interface                             : PGuid   ;
    function  Initialize (Packet         : Pointer ) : LxResult;
    procedure Reset      (Packet         : Pointer ) ;
    function  Copy       (Packet, From   : Pointer ) : LxResult;
    procedure Cleanup    (Packet         : Pointer ) ;
    function  Save       (Packet         : Pointer ;
                          N              : UInt32  ;
  			  WriteStream    : IUnknown) : LxResult;
    function  Load       (Packet         : Pointer ;
                          N              : UInt32  ;
  			  ReadStream     : IUnknown) : LxResult;
    function  Interpolate(Packet, P0, P1 : Pointer ;
  			  T              : Single  ) : LxResult;
    function  Blend      (Packet, P0, P1 : Pointer ;
     			  T              : Single  ;
                          Mode	         : Integer ) : LxResult;
    function  Invert     (Packet         : Pointer ) : LxResult;
  end;

  ILxPacketService = interface
  [LXu_PACKETSERVICE]
    function ScriptQuery     (  out VObj               ) : LxResult;
    function Lookup          (const Category : PChar   ;
                              const Name     : PChar   ;
                                    Offset   : PUInt32 ) : LxResult;
    function Name            (const Category : PChar   ;
                                    Offset   : UInt32  ;
                              const Name     : PPChar  ) : LxResult;
    function FastPacket      (      Vector   : IUnknown;
                                    Offset   : UInt32  ) : Pointer ;
    function CreateVectorType(const Category : PChar   ;
                                out VObj               ) : LxResult;
    function AddPacket       (      VType    : IUnknown;
                              const Name_    : PChar   ;
                                    Flags    : UInt32  ) : LxResult;
  end;

  ILxVectorType = interface
  [LXu_VECTORTYPE]
    function Category                         : PChar ;
    function Test    (Offset       : UInt32 ) : UInt32;
    function Count   (Type_        : UInt32 ) : UInt32;
    function ByIndex (Type_, Index : UInt32 ;
                      Flags        : PUInt32) : UInt32;
  end;

  ILxVectorStack = interface
  [LXu_VECTORSTACK]
    function Optional (      Offset : UInt32  ) : Pointer ;
    function Readable (      Offset : UInt32  ;
                         out Packet           ) : LxResult;
    function Writable (      Offset : UInt32  ;
                         out Packet           ) : LxResult;
    function SetPacket(      Offset : UInt32  ;
                             PDat   : Pointer ) : LxResult;
    function Push                               : LxResult;
    function Pop                                : LxResult;
  end;

  ILxVectorList = interface
  [LXu_VECTORLIST]
    function  Optional  (Offset  : UInt32  ) : Pointer ;
    function  Readable  (Offset  : UInt32  ;
                         Packet  : PPointer) : LxResult;
    function  Writable  (Offset  : UInt32  ;
                         Packet  : PPointer) : LxResult;
    function  SetPacket (Offset  : UInt32  ;
                         PDat    : Pointer ) : LxResult;
    function  Append    (Index   : PUInt32 ) : LxResult;
    function  Current                        : LxResult;
    function  SetCurrent(Index   : UInt32  ) : LxResult;
    function  Count                          : UInt32  ;
    procedure Clear                          ;
  end;

  ILxTextureEffect = interface
  [LXu_TEXTUREEFFECT]
   function &Type                           : Uint32  ;
   function TypeName                        : PChar   ;
   function Get     (      SV   : IUnknown;
                           Val  : PSingle ;
                           Item : Pointer ) : LxResult;
   function &Set    (      SV   : IUnknown;
                     const Val  : PSingle ;
                           Item : Pointer ) : LxResult;
  end;

  ILxPacketEffect = interface
  [LXu_PACKETEFFECT]
    function Packet (const Packet   : PPChar  ) : LxResult;
    function Count                              : UInt32  ;
    function ByIndex(      Index    : Integer ;
                     const Name     : PPChar  ;
                     const TypeName : PPChar  ;
                           &Type    : PInteger) : LxResult;
    function Get    (      Index    : Integer ;
                           Packet_  : Pointer ;
                           Val      : Single  ;
                           Item     : Pointer ) : LxResult;
    function &Set   (      Index    : Integer ;
                           Packet_  : Pointer ;
                     const Val      : PSingle ;
                           Item     : Pointer ) : LxResult;
  end;

implementation

end.

